package com.nondo.rdp.auth.security.auth.jwt;

import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.security.web.util.matcher.OrRequestMatcher;
import org.springframework.security.web.util.matcher.RequestMatcher;
import org.springframework.util.Assert;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 多个需要验证的url路径匹配
 *
 * @author linfeng
 * @since 2017/7/30
 */
public class ProcessPathRequestMatcher implements RequestMatcher {
    private RequestMatcher processingMatcher;

    public ProcessPathRequestMatcher(List<String> pathsToProcess) {
        Assert.notEmpty(pathsToProcess, "需要验证的url地址为空");
        List<RequestMatcher> m = pathsToProcess.stream().map(AntPathRequestMatcher::new).collect(Collectors.toList());
        processingMatcher = new OrRequestMatcher(m);
    }

    @Override
    public boolean matches(HttpServletRequest request) {
        return processingMatcher.matches(request);
    }
}
